@echo off

if "%~1" == "START" goto STARTIMAGE
if "%~1" == "INIT" goto INITIALIZE

:DEPLOY
VERIFY OTHER 2>nul
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
IF ERRORLEVEL 1 (
echo Unable to enable extensions
pause>nul
)
FOR /F "tokens=1,2,3,4,5,6,7,8,9* delims=$" %%A IN ("%~1") DO @if NOT ERRORLEVEL 1 (
SET event=%%A
SET lpside=%%B
SET mcounter=%%C
SET stepcounter=%%D
SET lastpos=%%E
SET nextplat=%%F
)


:NORMALDISP

set lpsteps=11
set /a lpsteps+=9*!mcounter!
if !lpsteps! LSS !stepcounter! goto GAMEOVER

if "!event!" == "1" goto JUMPDISP
if "!event!" == "0" (
if "!lastpos!" == "M" ( if "!lpside!" == "M" goto JUMPDISP)
)

set comple=0
set /a comple=!stepcounter!%%9
if "!comple!" == "0" (
    call:DISPSTAGE !nextplat!
) else (
    call:BLINES 1
)

goto EOF

REM only through NORMALDISP you can jump to JUMPDISP
:JUMPDISP
cls
set next=R
REM the lines to display
set dispsteps=0
set /a dispsteps=45+!stepcounter!
REM set lines=!stepcounter!
set lines=0

:LOOP
set comple=0
set /a comple=!lines!%%9
if "!lines!" == "!lpsteps!" (
    REM if !lines! LSS !stepcounter! goto GAMEOVER
    call:DISPLP !lpside!
    set /a lines+=6
) else (
    if "!comple!" == "0" (
        if !lines! GEQ !stepcounter! ( call:DISPSTAGE !next!)
        if "!next!" == "L" ( set next=R) else ( set next=L)
    ) else (
        if !lines! GEQ !stepcounter! ( call:BLINES 1)
    )
)

set /a lines+=1
if "!lines!" == "!dispsteps!" goto OUTLOOP
if !lines! GTR !dispsteps! (
    echo --- game will over ...
    echo --- lpside=!lpside!, event=!event!
    echo --- mcounter=!mcounter!, stepcounter=!stepcounter!, comple=!comple!
    echo --- lpsteps=!lpsteps!, lines=!lines!, dispsteps=!dispsteps!
    pause>nul
    goto GAMEOVER
)
goto LOOP

:OUTLOOP
goto EOF


:STARTIMAGE
cls
call:BLINES 20
echo       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo.
echo.
echo               little person game!
echo.
echo.
echo       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
call:BLINES 18
goto EOF


:INITIALIZE
cls
call:DISPSTAGE R
call:BLINES 8
call:DISPSTAGE L
call:BLINES 1
call:RIGHTSIDE
call:DISPSTAGE R
call:BLINES 8
call:DISPSTAGE L
call:BLINES 8
call:DISPSTAGE R
call:BLINES 8
goto EOF

:BLINES
REM the distance between the two horizon stage is 8.
for /L %%a in (1,1,%~1) do @echo.
REM first is 45 blanklines, when it becomes 45-9=36, the horizonline should be displayed.
goto EOF


:DISPLP
if "%~1" == "L" call:LEFTSIDE
if "%~1" == "R" call:RIGHTSIDE
IF "%~1" == "M" call:MIDSIDE
goto EOF

:RIGHTSIDE
REM the following is 33 blank characters.
REM #start#                                 #end#
REM the 33 blankspace is used to display the lp on the right!
echo                                     [-_-]
echo                                     /-+-\
echo                                    /^| + ^|\
echo                                   V ^|_+_^| V
echo                                      ^| ^|
echo                                      ^| ^|
echo                                     o0 0o
goto EOF

:MIDSIDE
REM the following is 22 blank characters.
REM #start#                      #end#
REM the 22 blankspace is used to display the lp on the middle!
echo                          [-_-]
echo                          /-+-\
echo                         /^| + ^|\
echo                        V ^|_+_^| V
echo                           ^| ^|
echo                           ^| ^|
echo                          o0 0o
goto EOF

:LEFTSIDE
REM the following is 7 blank characters.
REM #start#       #end#
REM the 7 blankspace is used to display the lp on the left!
echo           [-_-]
echo           /-+-\
echo          /^| + ^|\
echo         V ^|_+_^| V
echo            ^| ^|
echo            ^| ^|
echo           o0 0o
goto EOF

:DISPSTAGE
REM display the stage, its upward speed is 2 lines per time.
if "%~1" == "L" (
echo       %%%%%%%%%%%%%%%%%%%%%%%%%%
) else (
    if "%~1" == "R" (
    echo                                 %%%%%%%%%%%%%%%%%%%%%%%%%%
    )
)
goto EOF


:GAMEOVER
cls
call:BLINES 16
echo       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
echo.
echo.
echo.
echo                    Game Over!
echo.
echo.
echo.
echo       %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
call:BLINES 20
echo Game over at time:%date% %time%>lpgameover.log
goto EOF


:EOF
